# -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution    
#    Copyright (C) 2003-2010 NS-Team (<http://www.ns-team.fr>). All Rights Reserved
#    $Id$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import jasper_reports
from osv import osv,fields 
import pooler
import datetime
from mx import DateTime

def kderp_invoice_list( cr, uid, ids, data, context):
    try:
        year = data['form']['year']
    except:
        year = datetime.datetime.now().strftime("%Y")
    if year=='All':
        condition = "state not in ('draft','cancel')"
    else:
        condition = "state not in ('draft','cancel') and to_char(date,'YYYY')='%s'" % year
        
    cr.execute("Select id from kdvn_payment_from_client kpfc where %s" % condition)
    
    kderpfc_ids = []
    for idss in cr.fetchall():
        kderpfc_ids.append(idss[0])
    
    data['ids']=kderpfc_ids
    data['id'] = kderpfc_ids[0]
    
    return {'ids':kderpfc_ids,'parameters': {'period':year}}
jasper_reports.report_jasper(
   'report.kderp.report.invoice.list.pdf.hidden',
   'kdvn.payment.from.client',
   parser=kderp_invoice_list
)